<template>
  <span>
    <input
      v-model.trim="val"
      :disabled="disabled"
      :class="$style.inputNumber"
      class="ant-input-number-input"
      :min="min"
      type="number"
      @blur="sendValue($event)"
      @input="inputNum"
    />
  </span>
</template>
<script>
export default {
  props: {
    min: {
      type: Number,
      default: 0
    },
    value: {
      type: [String, Number],
      default: 0
    },
    disabled: {
      type: Boolean,
      default: false
    },
    precision: {
      type: Number,
      default: 4
    }
  },
  data() {
    return {
      val: this.value
    }
  },
  methods: {
    sendValue(e) {
      this.val = (this.val * 1).toFixed(this.precision)
      if (e.target.valueAsNumber < this.min) {
        this.val = this.min
      }
      if (isNaN(e.target.valueAsNumber)) {
        this.val = this.min
      }
      this.$emit('input', this.val)
    },
    inputNum() {
      console.log(this.value)
    }
  }
}
</script>
<style lang="less" module>
.inputNumber {
  border: 1px solid #9d9d9d !important;
  background: #fff !important;
}
</style>
